export function safeEncodeURIComponent(str) {
    try {
        return encodeURIComponent(str);
    } catch (e) {
        console.error('URI encoding failed:', str);
        return str;
    }
}

export function getThumbnailSrc(folder, filename) {
    return `/api/thumbnail?folder=${safeEncodeURIComponent(folder)}&name=${safeEncodeURIComponent(filename)}`;
}

// 判断文件类型
export function isImageFile(filename) {
    const ext = filename.toLowerCase().split('.').pop();
    return ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp', 'svg', 'tiff', 'ico'].includes(ext);
}

export function isVideoFile(filename) {
    const ext = filename.toLowerCase().split('.').pop();
    return ['mp4', 'webm', 'ogg', 'mov', 'avi', 'mkv', 'flv', 'wmv'].includes(ext);
}

export function isMovFile(filename) {
    const ext = filename.toLowerCase().split('.').pop();
    return ['mov'].includes(ext);
}

// 获取媒体源
export function getMediaSrc(folder, filename) {
    return `/api/file?folder=${safeEncodeURIComponent(folder)}&name=${safeEncodeURIComponent(filename)}`;
}

export function getExt(filename) {
    return filename.split('.').pop().toLowerCase();
}
